package com.vcaresolution.logistic.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.SimpleExpression;
import org.springframework.stereotype.Repository;

/**
 * The <code>UtilityDAO</code> class is a DAO Associated to do various 
 * options at DAO level
 *
 * @author Sneahl Shah
 * @version 1.0
 * @since ShipSoft 1.0
 */
@Repository
public class UtilityDAO extends BaseDAO{

	public Serializable insert(Object transientInstance) {
		return super.insert(transientInstance);
	}
	
	public void add(Object transientInstance) {
		super.add(transientInstance);
	}
	
	public void update(Object instance) {
		super.update(instance);
	}
	
	public void delete(Object persistentInstance) {
		super.delete(persistentInstance);
	}
	
	public <T> T findById(Class<T> objectClass, Serializable id) {
		return super.findById(objectClass, id);
	}
	
	public <T> List<T> findByAll(Class<T> objectClass) {
		return super.findByAll(objectClass);
	}
	
	@SuppressWarnings("unchecked")
	public <T> List<T> findByCondition(Class<T> objectClass, List<SimpleExpression> expressionList) {
		Criteria createCriteria = sessionFactory.getCurrentSession()
		.createCriteria(objectClass);
		
		for(SimpleExpression expression : expressionList){
			createCriteria.add(expression);
		}
		
		return createCriteria.list();
	}
}
